-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Layer: Fix POSTing data in data layer #12135
Conversation
Looks like a reasonable fix @donnapep - I'm less familiar with the POST requests and |
@dmsnell Looks like only Plans is using the HTTP layer. I've tested that and it's still working. Reader has some code to use it for tags, but it doesn't actually look like it's being called from anywhere yet. So I think we're good! |
@donnapep is the https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget/onprogress |
@dmsnell Looks like the info at that link is incorrect. The spec indicates I tested uploading on Chrome, FF, Safari and IE and it all works well. Cheers! |
Updated the MDN documentation. That was easy! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excellent work @donnapep, especially on updating the MDN docs!
also, I tested this on the live branch and it did not appear to break anything that I could see
…n the `query` wpcom's `req.post` has the signature: `params, [query], body, [callback]` which means positionnal arguments will move around based on the function's arity: 4: `params, query, body, callback` 3: `params, query, body` or `params, body, callback` 2: `params, body` With that in mind, the use of `compact` in the data-layer considerably complexifies the situation, as we can hit those various arities for many combinations of arguments. This tries to simplify the process while fixing a few edge cases already encountered in a few past PRs (#12135, #12839): If you want to pass `formData` (in `params`) with an `apiVersion` (in `query`), you NEED to pass a `body`, but any truth-y body will overwrite the `formData` in the HTTP request. This disqualifies the usage of `compact` as you - sometimes - want to pass a false-y values. (PR #12135) If you want to just pass an `apiVersion` (in `query`), you need - at least - another argument to have an arity of 3, which means you need to pass an empty body (PR #12839)
Passing empty objects for
body
andquery
causes form data to not be POSTed correctly, since wpcom runs explicit checks againstundefined
, or missing, parameters. Not passing these parameters to wpcom at all resolves the problem.